package com.highspeed.bdk.controller.logic;

import com.bianmaba.spring.data.jpa.domain.Result;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.highspeed.bdk.bean.entity.logic.LogicLink;
import com.highspeed.bdk.bean.entity.physical.PhysicalLink;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.base.IBdkBaseService;
import com.highspeed.bdk.service.logic.LogicLinkService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = {"logic_link"}, method = RequestMethod.POST)
@Api(tags = "逻辑链路")
public class LogicLinkController extends BdkCrudController<LogicLink, Integer> {

    @Autowired()
    private LogicLinkService logicLinkService;

    @Override
    protected IBdkBaseService getService() {
        return this.logicLinkService;
    }

    @ApiOperation(value = "保存逻辑链路列表", notes = "参数为JSON数据;<br/>" +
            "链路配置中中必须包含：leftApp.id和rightApp.id属性，不然不会与相关APP关联（已经关联的也会断掉）;<br/>")

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") LogicLink entity) {
        return super.save(entity);
    }

    @ApiOperation(value = "保存逻辑链路列表", notes = "参数为JSON数据;<br/>" +
            "每一个链路配置中中必须包含：leftApp.id和rightApp.id属性，不然不会与相关APP关联（已经关联的则会断掉）;<br/>")

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    @RequestMapping(value = "/saves", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") List<LogicLink> entity) {
        return super.save(entity);
    }

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    //根据appid查询逻辑链路
    @ApiOperation(value = "根据app id查询逻辑链路")
    @ApiImplicitParam(name = "id", value = "app id", dataType = "int", paramType = "query")
    @RequestMapping({"/find_by_app_id"})
    public Result findByAppId(Integer appId) {
        List<LogicLink> logicLinks = logicLinkService.findByAppId(appId);
        return new Result(true, null, logicLinks);
    }

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    //根据左右APP查询逻辑链路
    @ApiOperation(value = "根据两个App查询逻辑链路")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leftAppId", value = "左APP id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rightAppId", value = "右App id", dataType = "int", paramType = "query")}
    )
    @RequestMapping({"/find_by_two_app_id"})
    public Result findByTwoAppId(Integer leftAppId, Integer rightAppId) {
        LogicLink logicLink = logicLinkService.findByTwoAppId(leftAppId, rightAppId);
        return new Result(true, null, logicLink);
    }

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    //根据左右APP查询逻辑链路
    @ApiOperation(value = "根据两个App查询逻辑链路列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leftAppId", value = "左APP id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rightAppId", value = "右App id", dataType = "int", paramType = "query")}
    )
    @RequestMapping({"/find_all_by_two_app_id"})
    public Result findAllByTwoAppId(Integer leftAppId, Integer rightAppId) {
        List<LogicLink> logicLinks = logicLinkService.findAllByTwoAppId(leftAppId, rightAppId);
        return new Result(true, null, logicLinks);
    }


    //根据逻辑拓扑id查询逻辑链路

    @JSON(excludeProperties = {"data.*\\.preinstalledRedLogicTopology", "data.*\\.logicTopology", "data.*\\.leftLinks", "data.*\\.rightLinks"})
    @ApiOperation(value = "根据逻辑拓扑ID查询逻辑链路")
    @ApiImplicitParam(name = "id", value = "逻辑拓扑id", dataType = "int", paramType = "query")
    @RequestMapping({"/find_by_logic_topology_id"})
    public Result findByLogicTopologyId(Integer id) {
        List<LogicLink> logicLinks = logicLinkService.findByLogicTopologyId(id);
        return new Result(true, null, logicLinks);
    }
}
